#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>


char *wbuf = "Hello World\n";
char rbuf[128];

int main(void)
{
	printf("EmbedCharDev test\n");

	//打开文件, 写入数据
	int fd = open("/dev/chrdev", O_RDWR);
	write(fd, wbuf, strlen(wbuf));
	write(fd, wbuf, strlen(wbuf));
	close(fd);

	//打开文件, 读取文件内容
	fd = open("/dev/chrdev", O_RDWR);
	read(fd, rbuf, 128);
	printf("The content : [%s]\n", rbuf);
	close(fd);

	return 0;
}

//1. cat /proc/devices                 : 查看设备号<dev_id>
//2. mknod /dev/chrdev c <dev_id> 0    : 手动创建设备文件 /dev/chrdev
//3. 运行 ./chrdev_test 测试
//4. rm /dev/chrdev                    ：卸载删除
